import { createApp } from 'vue'
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import { ElConfigProvider } from 'element-plus';
import 'element-plus/theme-chalk/dark/css-vars.css'
import '@/assets/global.css'
import '@/assets/tailwind.css'
import i18n from "@/locales/index.js";
import App from '@/App.vue'
import router from '@/router/index.js'
import { GridLayout, GridItem } from 'grid-layout-plus'
import Loading from '@/components/common/Loading.vue';
import { userStore } from './store/user.js';

import socketService from '@/utils/socket.js';

const cctSocket = new socketService()
const currencySocket = new socketService()
const futures = new socketService()
const hycurrencySocket = new socketService()
cctSocket.init('https://new.uhx.io/cct/cct-websocket').connect()
cctSocket.on('connect', () => {
    userStore().setCctSocket(true)
    cctSocket.send('CONNECT\naccept-version:1.1\nheart-beat:10000,10000\n\n\u0000')
})
currencySocket.init('https://new.uhx.io/currency/websocket').connect()
currencySocket.on('connect', () => {
    userStore().setCurrencySocket(true)
    currencySocket.send('CONNECT\naccept-version:1.1\nheart-beat:10000,10000\n\n\u0000')
})
futures.init('https://new.uhx.io/futures/futures-websocket').connect()
futures.on('connect', () => {
    userStore().setFuturesSocket(true)
    futures.send('CONNECT\naccept-version:1.1\nheart-beat:10000,10000\n\n\u0000')
})
hycurrencySocket.init('https://new.uhx.io/hycurrency/websocket').connect()
hycurrencySocket.on('connect', () => {
    userStore().setHycurrencySocket(true)
    hycurrencySocket.send('CONNECT\naccept-version:1.1\nheart-beat:10000,10000\n\n\u0000')
})
const app = createApp(App)
app.component('ElConfigProvider', ElConfigProvider);
app.config.globalProperties.$cctSocket = cctSocket
app.config.globalProperties.$currencySocket = currencySocket
app.config.globalProperties.$hycurrencySocket = hycurrencySocket
app.config.globalProperties.$futures = futures
app.component('GridLayout', GridLayout)
app.component('GridItem', GridItem)
app.component('Loading', Loading)
const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)
app.use(pinia)
userStore().setCctSocket(false)
userStore().setCurrencySocket(false)
userStore().setHycurrencySocket(false)
userStore().setFuturesSocket(false)
app.use(router)
app.use(i18n)
app.mount('#app')